package com.situ.yB2C.address.Service.impl;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.situ.yB2C.address.Service.AddressService;
import com.situ.yB2C.address.dao.AddressDao;
import com.situ.yB2C.address.pojo.Address;
import com.situ.yB2C.area.dao.AreaDao;
import com.situ.yB2C.area.pojo.Area;
import com.situ.yB2C.util.ContextUtil;
@Service
public class AddressServiceImpl implements AddressService {
	
	
	@Autowired
	private AddressDao addressDao;
	@Autowired
	private AreaDao areaDao;
	
	@Override
	
	public int doaddAddress(Address address, Long userId, HttpSession session) {
		String createBy=ContextUtil.getBuyerUserCode(session);
		address.setUserId(userId);
		address.setIsDefault(0);//是否默认地址#1:是;0:否;
		address.setActiveFlag(1);
		address.setCreateBy(createBy);
		address.setCreateDate(new Date());
		return addressDao.insert(address);
		
	}

	@Override
	public List<Address> findAddressList() {
		return addressDao.selectList(Wrappers.emptyWrapper());
	}

	@Override
	public List<Area> findAreaListByParentCode(Integer parentCode) {
		
		return  areaDao.selectAreaByParent( parentCode);
	}

	@Override
	public int saveAddress(Address address) {
		
		return 0;
	}

}
